/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import entities.Labor;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author MinhDuc
 */
public class LaborTableModel extends AbstractTableModel {

    public static final int LABORID_INDEX = 0;
    public static final int NAME_INDEX = 1;
    public static final int ADDRESS_INDEX = 2;
    public static final int PHONENUMBER_INDEX = 3;
    public static final int STATUS_INDEX = 4;
    public static final int WEIGHT_INDEX = 5;
    public static final int HEIGHT_INDEX = 6;
    public static final int GENDER_INDEX = 7;
    public static final int FAMILYDETAIL_INDEX = 8;
    public static final int PERSONREFER_INDEX = 9;
    public static final int EXPERIENCE_INDEX = 10;
    public static final int SALARYGRADE_INDEX = 11;
    public static final int BUILDING_INDEX = 12;
    public static final int PERMANENT_INDEX = 13;
    private String[] columnNames = {"Labor ID", "Name", "Address", "Phone Number",
        "Status", "Weight", "Height", "Gender", "Family Detail", "Person Refer",
        "Experience", "Salary Grade", "Building", "Permanent"};
    private Vector<Labor> data;

    public LaborTableModel(Vector<Labor> data) {
        this.data = data;
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Labor labor = (Labor) data.get(rowIndex);
        switch (columnIndex) {
            case LABORID_INDEX:
                return labor.getLaborID();
            case NAME_INDEX:
                return labor.getName();
            case ADDRESS_INDEX:
                return labor.getAddress();
            case PHONENUMBER_INDEX:
                return labor.getPhoneNumber();
            case STATUS_INDEX:
                return labor.getStatus();
            case WEIGHT_INDEX:
                return labor.getWeight();
            case HEIGHT_INDEX:
                return labor.getHeight();
            case GENDER_INDEX:
                return labor.isGender();
            case FAMILYDETAIL_INDEX:
                return labor.getFamilyDetail();
            case PERSONREFER_INDEX:
                return labor.getPersonRefer();
            case EXPERIENCE_INDEX:
                return labor.getExperience();
            case SALARYGRADE_INDEX:
                return labor.getSalaryGrade();
            case BUILDING_INDEX:
                return labor.getBuilding();
            case PERMANENT_INDEX:
                return labor.isPermanent();
            default:
                return new Object();
        }
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        Labor labor = (Labor) data.get(rowIndex);
        switch (columnIndex) {
            case LABORID_INDEX:
                labor.setLaborID(String.valueOf(aValue));
                break;
            case NAME_INDEX:
                labor.setName(String.valueOf(aValue));
                break;
            case ADDRESS_INDEX:
                labor.setAddress(String.valueOf(aValue));
                break;
            case PHONENUMBER_INDEX:
                labor.setPhoneNumber(Integer.valueOf(String.valueOf(aValue)));
                break;
            case STATUS_INDEX:
                labor.setStatus(String.valueOf(aValue));
                break;
            case WEIGHT_INDEX:
                labor.setWeight(String.valueOf(aValue));
                break;
            case HEIGHT_INDEX:
                labor.setHeight(String.valueOf(aValue));
                break;
            case GENDER_INDEX:
                labor.setGender(Boolean.valueOf(String.valueOf(aValue)));
                break;
            case FAMILYDETAIL_INDEX:
                labor.setFamilyDetail(String.valueOf(aValue));
                break;
            case PERSONREFER_INDEX:
                labor.setPersonRefer(String.valueOf(aValue));
                break;
            case EXPERIENCE_INDEX:
                labor.setExperience(String.valueOf(aValue));
                break;
            case SALARYGRADE_INDEX:
                labor.setSalaryGrade(String.valueOf(aValue));
                break;
            case BUILDING_INDEX:
                labor.setBuilding(String.valueOf(aValue));
                break;
            case PERMANENT_INDEX:
                labor.setPermanent(Boolean.valueOf(String.valueOf(aValue)));
                break;
            default:
                System.out.println("INVALID INDEX");
        }
        fireTableCellUpdated(rowIndex, columnIndex);
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case LABORID_INDEX:
                return String.class;
            case NAME_INDEX:
                return String.class;
            case ADDRESS_INDEX:
                return String.class;
            case PHONENUMBER_INDEX:
                return Integer.class;
            case STATUS_INDEX:
                return String.class;
            case WEIGHT_INDEX:
                return String.class;
            case HEIGHT_INDEX:
                return String.class;
            case GENDER_INDEX:
                return Boolean.class;
            case FAMILYDETAIL_INDEX:
                return String.class;
            case PERSONREFER_INDEX:
                return String.class;
            case EXPERIENCE_INDEX:
                return String.class;
            case SALARYGRADE_INDEX:
                return String.class;
            case BUILDING_INDEX:
                return String.class;
            case PERMANENT_INDEX:
                return Boolean.class;
            default:
                return Object.class;
        }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        if (columnIndex == LABORID_INDEX) {
            return false;
        } else {
            return true;
        }
    }

    public void setData(Vector<Labor> data) {
        this.data = data;
    }
}
